<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

    <script type="module">
        import {consoleprint} from "./modules/first.js"

        //todo 回调函数
        function getData(callback) {
            setTimeout(function () {
                let name = "123"
                callback(name)
            })
        }

        getData((name) => {
            console.log(name)
        })

        // todo promise
        let p = new Promise(function (res, rej) {
            setTimeout(function () {
                res("abc")
            }, 1000)
        })
        p.then((data) => {
            console.log(data)
        });
        p.catch((data) => {
            return data
        })

        // // todo async
        //
        async function dd() { // 异步访求
            console.log("step 2")
            return "dd"
        }

        async function abcd() {
            try {
                console.log("step 1")
                let d=await dd()
                console.log(d)
                console.log("step 3")
            } catch (e) {
                console.log(e)
            }
        }

        abcd()


        // todo promise await
        let ppp = ()=>{
            return new Promise((resolve, reject) =>{
                setTimeout(function () {
                    resolve("promise + await")
                },1000)
            })
        }

        async function haha() {
            await ppp().then(res=>{
                console.log(res+" haha")
            }).catch(err=>{
                console.log(err)
            })
        }

        async function haha1() {
            let data =await ppp()
            console.log(data+" haha1")
        }
        haha()
        haha1()

    </script>
</head>
<body>

</body>
</html>